package test.y2022;

/**
 * Created By  醉美柳舞之众星捧月
 *
 * @author song
 * @date 2022/11/11 21:20
 */
public class November1 {


    /*   ()  不是 ()) */

    public static void main(String[] args) {
        String params = "))))))(((((((((((((((((((((((((((((((((((";
        System.out.println(minInsertions(params));
    }

    public static int minInsertions(String s) {
        char[] chars = s.toCharArray();
        int res = 0, left = 0;

        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '(') {
                left++;
            } else {
                // 没有左括号了，需要加一个左括号，res++
                if (left == 0) {
                    res++;
                } else {
                    left--;
                }
            }
        }
        return res + left;
    }

}
